package com.codeant.bikeindicatorapplication.tools;

import android.content.Context;
import android.media.MediaPlayer;
import com.codeant.bikeindicatorapplication.R;
import java.io.IOException;

public class SoundHelper {

    MediaPlayer mp ;

    public void init(Context context){
        mp = MediaPlayer.create(context, R.raw.bike);
    }

    public void play(boolean loop){
        try {
            if (mp != null){
                mp.stop();
            }
            mp.prepare();
            mp.start();
            mp.setLooping(loop);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void stop(){
        if (mp.isPlaying()){
            mp.stop();
        }
    }

    public void release(){
        if (mp != null){
            mp.release();
        }
    }

}



